<?php
/**
 * Created by PhpStorm.
 * User: Lian
 * Date: 2015/7/24
 * Time: 10:50
 */

namespace App\Services\Base;


use Illuminate\Support\Facades\Response;

class Rsp
{
    public $status;
    public $msg;
    public $rsp;

    private function __construct($rsp,$status,$msg) {
        $this->status = $status;
        $this->msg = $msg;
        $this->rsp = $rsp;
    }

    public function __toString() {
        return json_encode($this);
    }

    /**
     * 正确响应JSON
     * @param null $rsp  数据
     * @param int $status 状态
     * @param string $msg 状态说明
     * @return Rsp
     */
    public static function successMake($rsp=null,$status=0,$msg='') {
        $rsp = new Rsp($rsp,$status,$msg);
        $response = Response::make($rsp,200);
        $response->header('Content-Type', 'application/json');
        return $response;
    }

    /**
     * 错误响应JSON
     * @param null $rsp  数据
     * @param int $status 状态
     * @param string $msg 状态说明
     * @return Rsp
     */
    public static function errorMake($status,$msg,$rsp=null) {
        $rsp = new Rsp($rsp,$status,$msg);
        $response = Response::make($rsp,200);
        $response->header('Content-Type', 'application/json');
        return $response;
    }
}